<template>
  <div>
    <div class="title">
      <div class="title-icon" />
      <div>群伤管理事件</div>
      <div class="button">
        <el-button type="primary" style="margin-left: 20px" @click="back">
          返回
        </el-button>
      </div>
    </div>
    <div>
      <el-form ref="injuryFrom" :model="injuryFrom" label-width="130px">
        <el-row class="block">
          <el-form-item label="发生时间" class="item">
            <el-date-picker
              v-model="injuryFrom.happenTime"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="datetime"
              style="width: 100%"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="事件类型" class="item">
            <el-select v-model="injuryFrom.eventType">
              <el-option
                v-for="type in eventTypeList"
                :key="'searchEventType' + type.key"
                :value="type.key"
                :label="type.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="事件名称" class="item">
            <el-input v-model="injuryFrom.eventName"></el-input>
          </el-form-item>
        </el-row>
        <el-form-item label="事件描述" class="area">
          <el-input
            type="textarea"
            v-model="injuryFrom.eventDescribe"
          ></el-input>
        </el-form-item>
        <el-row type="flex">
          <el-form-item label="群伤人数" class="item">
            <el-row type="flex">
              <el-input v-model="injuryFrom.massNum" />
              <span>人</span>
            </el-row>
          </el-form-item>

          <el-row class="block">
            <el-form-item label="极高危" class="item">
              <el-row type="flex">
                <el-input v-model="injuryFrom.poleHighRisk" />
                <span>人</span>
              </el-row>
            </el-form-item>

            <el-form-item label="高危" class="item">
              <el-row type="flex">
                <el-input v-model="injuryFrom.highRisk" />
                <span>人</span>
              </el-row>
            </el-form-item>

            <el-form-item label="中危" class="item">
              <el-row type="flex">
                <el-input v-model="injuryFrom.inRisk" />
                <span>人</span>
              </el-row>
            </el-form-item>

            <el-form-item label="低危" class="item">
              <el-row type="flex">
                <el-input v-model="injuryFrom.lowRisk" />
                <span>人</span>
              </el-row>
            </el-form-item>
            <el-form-item label="死亡" class="item">
              <el-row type="flex">
                <el-input v-model="injuryFrom.deathRisk" />
                <span>人</span>
              </el-row>
            </el-form-item>
          </el-row>
        </el-row>
      </el-form>
    </div>
    <div align="right" class="save-button">
      <el-button type="primary" @click="save">保存</el-button>
    </div>
    <el-divider></el-divider>
    <div class="title">
      <div class="title-icon" />
      <div>群伤管理列表</div>
    </div>
    <el-form ref="searchForm" :model="searchForm" label-width="120px">
      <el-row class="block">
        <el-form-item label="时间段" class="range">
          <!-- <el-input v-model="searchForm.timeRange"></el-input> -->
          <el-date-picker
            v-model="searchForm.happenTime"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime"
            style="width: 100%"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="事件类型" class="item">
          <el-select v-model="searchForm.eventType" style="width: 100%">
            <el-option
              v-for="type in eventTypeList"
              :key="'searchEventType' + type.key"
              :value="type.key"
              :label="type.value"
            />
          </el-select>
        </el-form-item>
        <div class="button">
          <el-button @click="searchMassList">搜索</el-button>
          <el-button @click="reverse">重置</el-button>
        </div>
      </el-row>
    </el-form>
    <div class="table">
      <el-table :data="tableData" height="300" border>
        <el-table-column type="index" width="60" align="center">
          <template slot-scope="scope" align="center">
            {{
              (searchForm.pageNum - 1) * searchForm.pageSize + scope.$index + 1
            }}
          </template>
        </el-table-column>
        <el-table-column prop="happenTime" label="发生时间" align="center" />
        <el-table-column prop="eventType" label="事件类型" align="center" />
        <el-table-column prop="eventName" label="事件名称" align="center" />
        <el-table-column prop="massNum" label="群伤总人数" align="center" />
        <el-table-column prop="poleHighRisk" label="极高危" align="center" />
        <el-table-column prop="highRisk" label="高危" align="center" />
        <el-table-column prop="inRisk" label="中危" align="center" />
        <el-table-column prop="lowRisk" label="低危" align="center" />
        <el-table-column prop="deathRisk" label="死亡" align="center" />
        <el-table-column label="取消群伤" align="center">
          <template slot-scope="scope">
            <el-radio-group
              v-model="tableData[scope.$index].cancelMass"
              @change="modifyCancel(scope.row)"
            >
              <el-radio :label="1">是</el-radio>
              <el-radio :label="0">否</el-radio>
            </el-radio-group>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        class="pagination"
        :current-page.sync="searchForm.pageNum"
        :page-sizes="[10, 20, 30, 40, 50, 60, 70, 80, 90]"
        :page-size.sync="searchForm.pageSize"
        layout="sizes, prev, pager, next ,total"
        :total="count"
        background
        @size-change="pageInfoChange"
        @current-change="pageInfoChange"
      />
    </div>
  </div>
</template>

<script>
import { saveMass, massListByPojo, modifyCancel } from '@/api/triage/triage-new'

export default {
  name: 'InjuryGroup',
  data() {
    return {
      count: 0,
      injuryFrom: {},
      searchForm: {
        pageNum: 1,
        pageSize: 10,
        eventType: ''
      },
      eventTypeList: [
        { key: '1', value: '自然灾害' },
        { key: '2', value: '事故灾难' },
        { key: '3', value: '公共卫生事件' },
        { key: '4', value: '社会安全事' }
      ],
      tableData: []
    }
  },
  created() {
    this.getMassList()
  },
  methods: {
    getMassList() {
      this.searchForm.userId = this.$store.getters.userId
      massListByPojo(this.searchForm).then((res) => {
        if (res.code == 0) {
          this.tableData = res.data.list
          this.count = res.data.total
        }
      })
    },
    searchMassList() {
      this.searchForm.pageNum = 1
      this.getMassList()
    },
    reverse() {
      this.searchForm.timeRange = ''
      this.searchForm.eventType = ''
    },
    pageInfoChange() {
      this.getMassList()
    },
    save() {
      this.injuryFrom.userId = this.$store.getters.userId
      saveMass(this.injuryFrom).then((res) => {
        if (res.code == 0) {
          this.$message.success('保存成功')
          this.injuryFrom = {}
          this.reverse()
          this.searchMassList()
        } else {
          this.$message.error('保存失败')
        }
      })
    },
    modifyCancel(row) {
      modifyCancel(row).then((res) => {
        if (res.code == 0) {
          this.$message.success('操作成功')
          this.getMassList()
        } else {
          this.$message.error('操作失败')
        }
      })
    },
    back() {
      this.$router.push({ path: 'triage-list' })
    }
  }
}
</script>

<style lang="scss" scoped>
.title {
  display: flex;
  align-items: center;
  margin: 20px;
}
.title-icon {
  display: inline-block;
  width: 5px;
  height: 20px;
  border-radius: 28%;
  background-color: #4380ea;
  vertical-align: middle;
  margin-right: 6px;
}
.button {
  display: flex;
  margin-left: auto;
}
.item {
  min-width: 350px;
  max-width: 350px;
  span {
    margin-left: 12px;
  }
}
.range {
  float: left;
}
.block {
  width: 95%;
  .item {
    float: left;
    width: 350px;
  }
  span {
    margin-left: 12px;
  }
  .button {
    float: right;
  }
}
.area {
  width: 95%;
}
.save-button {
  width: 95%;
}
.table {
  width: 95%;
  padding: 0 0px 40px 40px;
}
</style>
